using DistributedGISA, Plots

# state constraint for each dimension
X = [@interval(-5,5), @interval(-5,5), @interval(-5,5)]
# number of divisions per dimension
d = 32
# create discrete space
ds = DiscreteSpace(X,[d,d,d])

# full system model
f(x,u) = (1.0*x[1]*x[1] + u[1], x[1] + 1.0*x[2]*x[2], x[2] + 1.0*x[3]*x[3])

# input constraint in interval form
u = [@interval(-1,1)]

# initial approximation of CIS
Rk = [[i,j,k] for i in 1:d for j in 1:d for k in 1:d]


# main computation

# create graph
G = create_graph(Rk,ds,u,f)
# select nonleaving cells
nlc = select_nonleaving_cells(G)
# update approximation of CIS
Rk = Rk[nlc]
# create cells for proccessing
bxs = create_boxes(Rk,ds)

arr = ConvexHullArray(bxs)
R1c = Projection(arr,[1,2])
R2c = Projection(arr,[2,3])
R3c = Projection(arr,[1,3])

# uncomment to select vertices of the cells forming the CIS and write to txt file
# writedlm("Rc_nonlinear.txt",unique!(vcat([collect(vertices(b)) for b in bxs]...)))
# for plotting
# R1c = 

println("Done!!!")
# end